store.js ➔ ... ➔ reducer   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 2
dl 0
loc 7
rs 9.4285
nop 2
1
import { combineReducers, applyMiddleware, createStore } from 'redux';
2
import { browserHistory } from 'react-router';
3
import { routerMiddleware } from 'react-router-redux';
4
import thunk from 'redux-thunk';
5
import apiMiddleware from '../middleware/api';
6
import * as reducers from '../state/reducers';
7
8
/**
9
 *
10
 * @param {*} initialState
11
 * @param {Object} handlers
12
 * @returns {function}
13
 * @see http://redux.js.org/docs/recipes/ReducingBoilerplate.html
14
 */
15
export function createReducer(initialState, handlers) {
16
  return function reducer(state = initialState, action) {
17
    if (handlers.hasOwnProperty(action.type)) {
18
      return handlers[action.type](state, action);
19
    } else {
20
      return state;
21
    }
22
  };
23
}
24
25
/**
26
 *
27
 * @returns {function}
28
 */
29
export function buildStore() {
30
  const rootReducer = combineReducers(reducers);
31
  const routerHistoryMiddleware = routerMiddleware(browserHistory);
32
33
  return applyMiddleware(thunk, apiMiddleware, routerHistoryMiddleware)(createStore)(rootReducer);
34
}
35